package top.lingkang.potato.network;

import com.dtflys.forest.config.ForestConfiguration;
import top.lingkang.potato.dto.ResponseResult;
import top.lingkang.potato.network.needtoken.UserClient;
import top.lingkang.potato.network.notoken.AccountClient;

/**
 * @author lingkang
 * @date 2021/9/19 12:44
 * @description
 */
public class HttpRequest {
    // 实例化Forest配置对象
    private static ForestConfiguration configuration = ForestConfiguration.configuration();

    public static AccountClient accountClient;
    public static UserClient userClient;

    public static void initHttpRequest() {
        // 连接池最大连接数，默认值为500
        configuration.setMaxConnections(20);
        // 每个路由的最大连接数，默认值为500
        configuration.setMaxRouteConnections(20);
        // 请求超时时间，单位为毫秒, 默认值为3000
        configuration.setTimeout(3000);
        // 连接超时时间，单位为毫秒, 默认值为2000
        configuration.setConnectTimeout(3000);
        // 请求失败后重试次数，默认为0次不重试
        configuration.setRetryCount(1);
        // 单向验证的HTTPS的默认SSL协议，默认为SSLv3
        // configuration.setSslProtocol(SSLUtils.SSLv3);
        // 打开或关闭日志，默认为true
        //configuration.setLogEnabled(true);
        //configuration.setLogEnabled(false);
        accountClient = configuration.createInstance(AccountClient.class);
        userClient = configuration.createInstance(UserClient.class);
    }

    public static void main(String[] args) {
        initHttpRequest();
        ResponseResult login = accountClient.login("123", "123");
        System.out.println(login);
        ResponseResult userInfo = userClient.getUserInfo();
        System.out.println(userInfo);
        System.out.println(123);
    }

}
